package com.nari.ruist.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nari.common.log.annotation.Log;
import com.nari.common.log.enums.BusinessType;
import com.nari.common.security.annotation.PreAuthorize;
import com.nari.ruist.domain.RstInterface;
import com.nari.ruist.service.IRstInterfaceService;
import com.nari.common.core.web.controller.BaseController;
import com.nari.common.core.web.domain.AjaxResult;
import com.nari.common.core.utils.poi.ExcelUtil;
import com.nari.common.core.web.page.TableDataInfo;

/**
 * 接口清单 Controller
 *
 * @author nari
 * @date 2021-04-02
 */
@RestController
@RequestMapping("/interface")
public class RstInterfaceController extends BaseController {
    @Autowired
    private IRstInterfaceService rstInterfaceService;

    /**
     * 查询接口清单 列表
     */
    @PreAuthorize(hasPermi = "system:interface:list")
    @GetMapping("/list")
    public TableDataInfo list(RstInterface rstInterface) {
        startPage();
        List<RstInterface> list = rstInterfaceService.selectRstInterfaceList(rstInterface);
        return getDataTable(list);
    }

    /**
     * 导出接口清单 列表
     */
    @PreAuthorize(hasPermi = "system:interface:export")
    @Log(title = "接口清单 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RstInterface rstInterface) throws IOException {
        List<RstInterface> list = rstInterfaceService.selectRstInterfaceList(rstInterface);
        ExcelUtil<RstInterface> util = new ExcelUtil<RstInterface>(RstInterface.class);
        util.exportExcel(response, list, "interface");
    }

    /**
     * 获取接口清单 详细信息
     */
    @PreAuthorize(hasPermi = "system:interface:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(rstInterfaceService.selectRstInterfaceById(id));
    }

    /**
     * 新增接口清单
     */
    @PreAuthorize(hasPermi = "system:interface:add")
    @Log(title = "接口清单 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RstInterface rstInterface) {
        return toAjax(rstInterfaceService.insertRstInterface(rstInterface));
    }

    /**
     * 修改接口清单
     */
    @PreAuthorize(hasPermi = "system:interface:edit")
    @Log(title = "接口清单 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RstInterface rstInterface) {
        return toAjax(rstInterfaceService.updateRstInterface(rstInterface));
    }

    /**
     * 删除接口清单
     */
    @PreAuthorize(hasPermi = "system:interface:remove")
    @Log(title = "接口清单 ", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(rstInterfaceService.deleteRstInterfaceByIds(ids));
    }
}
